﻿namespace Sidvall.AuthorizationManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class ActionOption : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.AuthorizationManager.Data.IActionOption
    {
        #region Public Members

        #region Name

        private string _Name;
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        { 
            get
            {
                return _Name;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Name = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                    OnBeforeNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Name", eventData.Value, true, true);
                        OnAfterNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public ActionOption Copy()
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Copy(this);
        }
        public ActionOption Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IActionOption item)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Import(this, item);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IActionOption item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Initialize(this, settings);
        }

        #endregion

        #region IActionOption Members

        string global::Sidvall.AuthorizationManager.Data.IActionOption.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public ActionOption()
        {
        }
        public ActionOption(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public ActionOption(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.ActionOptionManager.Initialize(this);
        }

        #endregion
    }
}